"""LeadTag schemas for API validation."""

from __future__ import annotations

from datetime import datetime
from pydantic import BaseModel, Field, ConfigDict

from ..schemas.tag import TagResponse


class LeadTagBase(BaseModel):
    """LeadTag基础schema."""

    lead_id: int = Field(..., description="客户ID")
    tag_id: int = Field(..., description="标签ID")
    confidence: float = Field(default=1.0, ge=0.0, le=1.0, description="置信度")
    source: str = Field(default="manual", description="来源：ai/rule/manual")


class LeadTagCreate(LeadTagBase):
    """创建LeadTag的schema."""

    pass


class LeadTagUpdate(BaseModel):
    """更新LeadTag的schema（所有字段可选）."""

    confidence: float | None = Field(None, ge=0.0, le=1.0)
    source: str | None = None


class LeadTagInDB(LeadTagBase):
    """LeadTag数据库schema."""

    model_config = ConfigDict(from_attributes=True)

    id: int
    created_at: datetime
    updated_at: datetime


class LeadTagResponse(LeadTagInDB):
    """LeadTag响应schema（包含Tag详情）."""

    tag: TagResponse | None = None
